<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class CreatePassportDataTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('passport_data', function (Blueprint $table) {
            $table->id()->from(config('migration.from'));

            $table->bigInteger('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade')->onUpdate('cascade');

            $table->string('serial_number')->nullable();
            $table->date('issue_date')->nullable();
            $table->string('department_code')->nullable();
            $table->string('issued_by')->nullable();

            $table->bigInteger('first_photo_id')->unsigned()->nullable()->comment('Первая страница');
            $table->foreign('first_photo_id')->references('id')->on('files')->onDelete('set null');

            $table->bigInteger('second_photo_id')->unsigned()->nullable()->comment('Страница последней прописки');
            $table->foreign('second_photo_id')->references('id')->on('files')->onDelete('set null');

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('passport_data');
    }
}
